package com.zds.zhouyi.ui;

import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.zds.zhouyi.R;
import com.zds.zhouyi.util.ResUtil;

public class NormalDialog extends Dialog {

    public NormalDialog(Context context) {
        super(context);
    }

    public NormalDialog(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {
        private Context context;
        private String content;
        private String posText = ResUtil.getString(R.string.confirm);
        private String negText = ResUtil.getString(R.string.cancel);
        private DialogInterface.OnClickListener positiveButtonClickListener;
        private DialogInterface.OnClickListener negativeButtonClickListener;

        public Builder(Context context) {
            this.context = context;
        }

        public NormalDialog.Builder setContent(String content) {
            this.content = content;
            return this;
        }

        public NormalDialog.Builder setPositiveButton(DialogInterface.OnClickListener listener) {
            this.positiveButtonClickListener = listener;
            return this;
        }

        public NormalDialog.Builder setNegativeButton(DialogInterface.OnClickListener listener) {
            this.negativeButtonClickListener = listener;
            return this;
        }

        public NormalDialog.Builder setPositiveBtnText(String text) {
            this.posText = text;
            return this;
        }

        public NormalDialog.Builder setNegativeBtnText(String text) {
            this.negText = text;
            return this;
        }

        public NormalDialog create() {
            LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //为自定义弹框设置主题
            NormalDialog customDialog = new NormalDialog(context, R.style.CustomDialog);
            View view = layoutInflater.inflate(R.layout.dialog_normal, null);
            customDialog.addContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
            //设置弹框内容
            TextView tvContent = ((TextView) view.findViewById(R.id.tv_tip));
            TextView tvConfirm = ((TextView) view.findViewById(R.id.tv_confirm));
            TextView tvCancel = ((TextView) view.findViewById(R.id.tv_cancel));
            if (!TextUtils.isEmpty(content)) {
                tvContent.setText(content);
            }
            tvConfirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    positiveButtonClickListener.onClick(customDialog, DialogInterface.BUTTON_POSITIVE);
                    customDialog.dismiss();
                }
            });


            tvCancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    negativeButtonClickListener.onClick(customDialog, DialogInterface.BUTTON_NEGATIVE);
                    customDialog.dismiss();
                }
            });

            customDialog.setContentView(view);
            return customDialog;
        }
    }
}
